//
// Copyright (c) 2002-2010 "Neo Technology,"
//     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// This file is part of Neo4j.
// 
// Neo4j is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
// 
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.graphdb
{
    /// <summary> 
    /// Encapsulates information about the current traversal position.
    /// The TraversalPosition is mainly used in
    /// <seealso cref="StopEvaluator.IsStopNode(TraversalPosition)"/> and
    /// <seealso cref="ReturnableEvaluator.IsReturnableNode(TraversalPosition)"/> for
    /// evaluating whether a position in a traversal is a point where the traversal
    /// should stop or if the node at that position is to be part of the result
    /// respectively.
    ///  </summary>
    public interface TraversalPosition
    {
        #region Implementations

        ///<summary> 
        /// Return the current node.
        /// </summary>
        ///<returns> The current node </returns>
        Node CurrentNode();
        ///<summary> 
        /// Returns the previous node.
        ///If this TraversalPosition represents the start node <code>null</code> is
        ///returned.
        /// </summary>
        ///<returns> The previous node, or <code>null</code> </returns>
        Node PreviousNode();
        ///<summary> 
        /// Return the last relationship traversed.
        ///
        ///If this TraversalPosition represents the start node <code>null</code> is
        ///returned.
        /// </summary>
        ///<returns> The last relationship traversed, or <code>null</code>. </returns>
        Relationship LastRelationshipTraversed();
        ///<summary> 
        /// Returns the current traversal depth.
        ///
        ///The traversal depth is the length of the path taken to reach the current
        ///traversal position. This is not necessarily the length of shortest path
        ///from the start node to the node at the current position. When traversing
        ///<seealso cref="Order.BREADTH_FIRST"/> the depth is the
        ///length of the shortest path from the start node to the node at the
        ///current position, but when traversing {@link Order.DEPTH_FIRST
        ///depth first} there might exist shorter paths from the start node to the
        ///node at this position.
        /// </summary>
        ///<returns>
        ///  The current traversal depth </returns>
        int Depth();
        ///<summary> 
        /// Returns the number of nodes returned by traverser so far.
        /// </summary>
        ///<returns> The number of returned nodes. </returns>
        int ReturnedNodesCount();
        ///<summary> 
        /// Returns <code>true</code> if the current position is anywhere except on
        ///the start node, <code>false</code> if it is on the start node. This is
        ///useful because code in <seealso cref="StopEvaluator"/>
        ///<seealso cref="ReturnableEvaluator"/> usually have to treat the edge
        ///case of the start node separately and using this method makes that code a
        ///lot cleaner. This allows for much cleaner code where <code>null</code>
        ///checks can be avoided for return values from
        ///<seealso cref="LastRelationshipTraversed()"/> and <seealso cref="PreviousNode()"/>, such as
        ///in this example:
        ///
        ///<pre>
        ///<code>
        ///public boolean <seealso cref="StopEvaluator.IsStopNode"/>( TraversalPosition currentPos )
        ///{
        ///    // Stop at nodes reached through a SOME_RELATIONSHIP.
        ///    return currentPos.notStartNode()
        ///        &amp;&amp; currentPos.<seealso cref="LastRelationshipTraversed() LastRelationshipTraversed"/>().<seealso cref="Relationship.isType(RelationshipType) isType"/>(
        ///            <seealso cref="RelationshipType MyRelationshipTypes.SOME_RELATIONSHIP"/> );
        ///}
        ///</code>
        ///</pre>
        /// </summary>
        ///<returns> <code>true</code> if the this TraversalPosition is not at the
        ///        start node, <code>false</code> if it is. </returns>
        bool NotStartNode();
        ///<summary> 
        /// Returns <code>true</code> if the current position is the start node,
        ///<code>false</code> otherwise. This is useful because code in
        ///<seealso cref="StopEvaluator"/> <seealso cref="ReturnableEvaluator "/> usually
        ///have to treat the edge case of the start node separately and using this
        ///method makes that code a lot cleaner. This allows for much cleaner code
        ///where <code>null</code> checks can be avoided for return values from
        ///<seealso cref="LastRelationshipTraversed()"/> and <seealso cref="PreviousNode()"/>, such as
        ///in this example:
        ///
        ///<pre>
        ///<code>
        ///public boolean <seealso cref="ReturnableEvaluator.IsReturnableNode(TraversalPosition) IsReturnableNode"/>( TraversalPosition currentPos )
        ///{
        ///    // The start node, and nodes reached through SOME_RELATIONSHIP
        ///    // are returnable.
        ///    return currentPos.isStartNode()
        ///        || currentPos.<seealso cref="LastRelationshipTraversed() LastRelationshipTraversed"/>().<seealso cref="Relationship.isType(RelationshipType)"/>(
        ///            <seealso cref="RelationshipType MyRelationshipTypes.SOME_RELATIONSHIP"/> );
        ///}
        ///</code>
        ///</pre>
        /// </summary>
        ///<returns> <code>true</code> if the this TraversalPosition is at the start
        ///        node, <code>false</code> if it is not. </returns>
        bool IsStartNode();

        #endregion
    }
}